/**
 * @author Mie Plougstrup, Anders Abildgaard, Bo Stokholm 
 * @Version 16-12-2014
 */
package ctrLayer;


import java.util.ArrayList;

import modelLayer.ChartecCode;
import dbLayer.DbChartecCode;
/**
 * 
 * @author Bo Stokholm, Mie Plougstrup
 *
 */
public class CtrChartecCode {
	private DbChartecCode dbcc;

	public CtrChartecCode(){
		dbcc = new DbChartecCode();
	}

	/**
	 * Retrieves a chartec code object from the class
	 * DbChartecCode. The methods find to object by
	 * it's chartec code id.
	 * @param int code
	 * @return ChartecCode object
	 */
	public ChartecCode retrieveChartecCode(int code){
		return dbcc.retrieveByCode(code);
	}

	/**
	 * Method for retrieving all ChartecCode objects.
	 * 
	 * @return		An ArrayList of ChartecCode objects.
	 */
	public ArrayList<ChartecCode> retrieveAll() {
		return dbcc.retrieveAll();
	}

	/**
	 * Updates a charteccode object in the database
	 * and returns it from the database.
	 * @param ChartecCode cc
	 * @return ChartecCode object
	 */
	public void update(ChartecCode cc) throws Exception{
		dbcc.update(cc);
	//	return dbcc.retrieveByCode(cc.getChartecCode());
	}

	/**
	 * Deletes a charteccode from the database.
	 * @param ChartecCode cc
	 */
	public void delete(ChartecCode cc) throws Exception{
		dbcc.delete(cc);
		
	}	

	/**
	 * Method for creating a chartecCode and inserting it into the database.
	 * 
	 * @param chartecCode
	 * @param shippingPlace
	 * @param hasDeliveryNo
	 * @return The newly created chartecCode
	 * @throws Exception
	 */
	public ChartecCode create(int chartecCode, String shippingPlace, boolean hasDeliveryNo) throws Exception {
		ChartecCode ctc = new ChartecCode(chartecCode, shippingPlace, hasDeliveryNo);
		dbcc.insert(ctc);
		return ctc;
	}
}
